package reflect;

import reflect.annotation.AutoRunClass;
import reflect.annotation.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args)throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入类名:");
        Class<?> cls = Class.forName(sc.nextLine());
        if(cls.isAnnotationPresent(AutoRunClass.class)){
            Method[] methods = cls.getMethods();
            for (Method method : methods) {
                if (method.isAnnotationPresent(AutoRunMethod.class)){
                    Object obj = cls.newInstance();
                    System.out.println(method.getName()+"()方法被标注了");
                    method.invoke(obj);
                }else{
                    System.out.println(method.getName()+"()该方法没有被标注");
                }
            }
        }else {
            System.out.println("该类没有被标注");
        }
    }
}
